﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace Studio.Windows.UserControls
{
    public partial class ImpressLogo : UserControl
    {
        public ImpressLogo()
        {
            InitializeComponent();
            _original = this.Location;
            _dimension = this.Size;
        }

        // Bad idea, but it works.
        bool _internal = false;

        private Point _original;
        private Size _dimension;

        private ImpressDirections _direction = ImpressDirections.DIRECTION_BOTTOM_LEFT;

        public ImpressDirections Direction
        {
            get { return _direction; }
            set { _direction = value; }
        }

        private float _impressRatio = 3.0f;

        public float ImpressRatio
        {
            get { return _impressRatio; }
            set { _impressRatio = value; }
        }


        private void pictureBoxLogo_MouseEnter(object sender, EventArgs e)
        {
            _internal = true;
            pictureBoxLogo.BorderStyle = BorderStyle.FixedSingle;
            this.Location = ImpressLocation;
            this.Size = ImpressSize;
            _internal = false;
        }


        private void pictureBoxLogo_MouseLeave(object sender, EventArgs e)
        {
            _internal = true;
            pictureBoxLogo.BorderStyle = BorderStyle.Fixed3D;
            this.Location = _original;
            this.Size = _dimension;
            _internal = false;
        }


        public Point ImpressLocation
        {
            get
            {
                Point impressLocation = this.Location;
                float offset = _impressRatio - 1.0f;

                float w = _dimension.Width;
                float h = _dimension.Height;
                switch (_direction)
                {
                    case ImpressDirections.DIRECTION_BOTTOM_LEFT:
                        impressLocation = new Point((int)(_original.X - offset * w), _original.Y);
                        break;
                    case ImpressDirections.DIRECTION_BOTTOM_RIGHT:
                        break;
                    case ImpressDirections.DIRECTION_TOP_LEFT:
                        impressLocation = new Point((int)(_original.X - offset * w), (int)(_original.Y - offset * h));
                        break;
                    case ImpressDirections.DIRECTION_TOP_RIGHT:
                        impressLocation = new Point(_original.X, (int)(_original.Y - offset * h));
                        break;
                }
                return impressLocation;
            }

        }

        public Size ImpressSize
        {
            get
            {
                int w = (int) (_dimension.Width * _impressRatio);
                int h = (int) (_dimension.Height * _impressRatio);
                return new Size(w, h);
            }
        }

        private void SaveOrigin()
        {
            if (false == _internal)
            {
                _original = this.Location;
                _dimension = this.Size;
            }
        }

        private void ImpressLogo_Resize(object sender, EventArgs e)
        {
            SaveOrigin();
        }

        private void ImpressLogo_LocationChanged(object sender, EventArgs e)
        {
            SaveOrigin();
        }

        private void ImpressLogo_Move(object sender, EventArgs e)
        {
            SaveOrigin();
        }

        private void pictureBoxLogo_Click(object sender, EventArgs e)
        {
            this.OnClick(e);
        }

        
        
    }
}
